package com.itheima.health.controller.admin;

import com.itheima.health.common.MessageConst;
import com.itheima.health.pojo.CheckGroup;
import com.itheima.health.pojo.CheckItem;
import com.itheima.health.result.PageResult;
import com.itheima.health.result.QueryPageBean;
import com.itheima.health.result.Result;
import com.itheima.health.service.CheckGroupService;
import com.itheima.health.service.ReportService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;

/**
 * 数据统计
 **/
@RestController
@RequestMapping("/report")
@Slf4j
public class ReportController {

    @Autowired
    private ReportService reportService;

    /**
     * 会员数量折线图
     * @return
     */
    @GetMapping("/getMemberReport")
    public Result getMemberReport(){
        Map<String, Object> data = reportService.getMemberReport();
        return new Result(true, MessageConst.GET_MEMBER_NUMBER_REPORT_SUCCESS, data);
    }
    /**
     * 套餐预约占比饼形图
     * @return
     */
    @GetMapping("/getSetmealReport")
    public Result getSetmealReport() {
        Map<String, Object> data = reportService.getSetmealReport();
        return new Result(true, MessageConst.GET_SETMEAL_COUNT_REPORT_SUCCESS, data);
    }

    /**
     * 统计分析运营表
     * @return
     */
    @GetMapping("/getBusinessReportData")
    public Result getBusinessReportData() {
        Map<String, Object> data = reportService.getBusinessReportData();
        return new Result(true,MessageConst.GET_BUSINESS_REPORT_SUCCESS , data);
    }
    /**
     * 导出运营数据成Excel表格
     * @param response
     * @return
     */
    @RequestMapping("/exportBusinessReport")
    public Result exportBusinessReport(HttpServletResponse response) {
        Map<String, Object> result = reportService.getBusinessReportData();
        reportService.exportBusinessReport(response, result);
        try {
            return null;
        } catch (Exception e) {
            return new Result(false, MessageConst.GET_BUSINESS_REPORT_FAIL);
        }
    }
}
